Quality control and filtering results from cellranger

Sample info and environment setup

PRJNA579391

setwd("/media/jacopo/Elements/re_align/healthy/PRJNA579391/SAMN13110907/SRR10343068/")
# Load the libraries (from Sarah script + biomart)
library(tidyverse) # packages for data wrangling, visualization etc
library(Seurat) # scRNA-Seq analysis package
library(clustree) # plot of clustering tree 
library(ggsignif) # Enrich your 'ggplots' with group-wise comparisons
library(clusterProfiler) #The package implements methods to analyze and visualize functional profiles of gene and gene clusters.
library(org.Hs.eg.db) # Human annotation package neede for clusterProfiler
library(ggrepel) # extra geoms for ggplo2
library(patchwork) #multiplots
library(reticulate)

Load and process cellranger data

Load and do the QC for the cellranger data

dat <- Read10X(data.dir ="./out/counts_filtered/")
dat <- CreateSeuratObject(dat) # Create the seurat object from the 10x data
kb.initial <- dat@assays[["RNA"]]@counts@Dim[[2]]
cat("Initial number of cells:", kb.initial, 
    "\nNumber of genes:",  dat@assays[["RNA"]]@counts@Dim[[1]])
## Initial number of cells: 8368 
## Number of genes: 36601

Quality Control

Empty cells were already filtered, check for % mt RNA and death markers:

# first calculate the mitochondrial percentage for each cell
dat$percent_mt <- PercentageFeatureSet(dat, pattern="^MT.")
# make violin plots
mt_rna = 20
max_counts = 20000


# Check some feature-feature relationships
# % mt RNA vs n Counts, n Features vs n Counts
VlnPlot(dat, features = c("nCount_RNA", "nFeature_RNA", "percent_mt"))  + geom_hline(yintercept=mt_rna, linetype = "dotted")

plot1 <- FeatureScatter(dat, feature1 = "nCount_RNA", feature2 = "percent_mt")
plot1 <- plot1 + geom_hline(yintercept=mt_rna, linetype = "dotted")
plot2 <- FeatureScatter(dat, feature1 = "nCount_RNA", feature2 = "nFeature_RNA")
plot2 <- plot2 + geom_vline(xintercept = max_counts, linetype = "dotted")
plot1 

plot2

##  cells retained by mt RNA content ( 20 %): 6779 
##  percentage of retained cells: 81.01 %
## cells retained by counts ( 20000 ): 6766 
##  percentage of retained cells: 80.86 %

Check the distribution of the cells with low counts and control death markers:

min_counts = 200


hist(dat@meta.data$nCount_RNA, breaks = 100, xlab = "Counts")

hist(dat@meta.data$nCount_RNA, breaks = 500, xlab = "Counts", xlim = c(0,5000))

hist(dat@meta.data$nCount_RNA, breaks = 10000, xlab = "Counts", xlim = c(0,1000))
abline(v=min_counts, col="red", lty = 3)

# Subset the dataset to focus only on those cells with low counts
dat.lowcount <- subset(dat, subset = nCount_RNA < min_counts)

# Get the mean of the counts for each gene and sort them decreasing
meanCounts <- rowMeans(GetAssayData(object = dat.lowcount, slot = 'counts'))
meanCounts <- sort(meanCounts, decreasing = T)

# A boxplot can help to observe the distribution of the means
#boxplot(meanCounts)

# Print the most highly expressed genes
head(meanCounts, 20)
##    MALAT1     RPLP1     RPS12      RPS6     RPS18     RPS3A    RPL13A     RPS4X 
## 2.3870968 1.3479263 1.1981567 1.1866359 1.1658986 1.1152074 1.0622120 1.0322581 
##     RPL26     RPS23     RPL13     RPL41      RPL7    EEF1A1     RPL21      PTMA 
## 0.9838710 0.9827189 0.9792627 0.9781106 0.9654378 0.9377880 0.9262673 0.9124424 
##     RPL34     RPS24     RPL17      RPS2 
## 0.9043779 0.8479263 0.8444700 0.8341014
## cells retained by counts ( 200 ): 5897 
##  percentage of retained cells: 70.47 %

dir.create("result")
saveRDS(dat, file = "./result/SRR10343068_clean_QC.RDS")

Feature selection

#Normalize
dat <- NormalizeData(dat)
# Find the first 4000 variabe features
dat <- FindVariableFeatures(dat, selection.method = "vst", nfeatures = 4000)

Data scaling

Set mean expression to 0 and variance across 1 to avoid highly expressed genes drive the forwarding analyses. Since negative expression is meaningless, scaled data are useful only for UMAP and clustering

# scale data, the scaled data are saved in:
# dat[["RNA"]]@scale.data

all.genes <- rownames(dat)

dat <- ScaleData(dat, vars.to.regress = c("percent_mt","nCount_RNA"))

Dimensionality reduction

dat <- RunPCA(dat, features = VariableFeatures(object = dat), verbose = F, seed.use = 1)
print(dat[["pca"]], dims = 1:5, nfeatures = 5)
## PC_ 1 
## Positive:  CYTL1, CNRIP1, HBD, KLF1, APOC1 
## Negative:  TMSB4X, LGALS1, CYBA, VIM, CORO1A 
## PC_ 2 
## Positive:  HBB, APOC1, CA1, HBD, AHSP 
## Negative:  SPINK2, AIF1, C1QTNF4, HOPX, MGST1 
## PC_ 3 
## Positive:  IGLL1, DNTT, VPREB1, CD79B, VPREB3 
## Negative:  S100A6, S100A4, LYZ, CST3, LGALS1 
## PC_ 4 
## Positive:  MPO, PRTN3, AZU1, ELANE, MIF 
## Negative:  JCHAIN, IRF7, CCDC50, CD74, UGCG 
## PC_ 5 
## Positive:  DNTT, VPREB1, CD79B, VPREB3, IGLL1 
## Negative:  CD164, FCER1A, GP1BB, AL157895.1, PBX1

UMAP

UMAP is a graph-based method of clustering. The first step in this process is to construct a KNN graph based on the euclidean distance in PCA space:

dat <- FindNeighbors(dat, dims = 1:20)

The graph now can be used as input for the function runUMAP()

dat <- RunUMAP(dat, dims = 1:20, seed.use = 1)
DimPlot(dat, reduction = 'umap', seed = 1)

Final plots:

## QC metrics

## markers